﻿using BLL;
using Common.BaseSoa;
using Common.Util;
using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace WebManage.Controllers
{
    public class LoginController : Controller
    {
        [BaseController(IsCheck = false)]
        //
        // GET: /Login/
        public ActionResult Index()
        { 
                return View();
            
        }
        #region 登录
        [HttpPost]
        public JsonResult GetLogin(string userName, string userPwd)
        {
            try
            {
                AccountBLL bll = new AccountBLL();
                Admin model = bll.GetLogin(userName, userPwd);
                Responses re = new Responses();
                if (model == null)
                {

                    return Json("", JsonRequestBehavior.AllowGet);
                }
                else
                {
                    CookieHelper.Save("pcnfs_UserId", Encrypt.Encode(model.ID.ToString()), 3);
                    CookieHelper.Save("pcnfs_user_name", Encrypt.Encode(model.UserName.ToString()), 3);
                    
                    return Json(model, JsonRequestBehavior.AllowGet);
                }
            }
            catch (Exception)
            {
                return Json("", JsonRequestBehavior.AllowGet);
            }

        }
        #endregion

        /// <summary>
        /// 退出时清楚Cookie
        /// </summary>
        /// <returns></returns>
        public ActionResult ClearSession()
        {

            CookieHelper.Remove("pcnfs_UserId");
            CookieHelper.Remove("pcnfs_user_name");
            CookieHelper.Remove("pcnfs_type");
            CookieHelper.Remove("pcnfs_IsAdmin");
            return Redirect("/Login/Login");
        }
	}
}